package com.ruicar.afs.cloud.finance.task;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruicar.afs.cloud.common.job.core.biz.model.ReturnT;
import com.ruicar.afs.cloud.common.job.core.handler.annotation.AfsJob;
import com.ruicar.afs.cloud.common.job.core.handler.annotation.AfsJobHandler;
import com.ruicar.afs.cloud.finance.common.entity.FinanceVirtualAccount;
import com.ruicar.afs.cloud.finance.common.service.FinanceVirtualAccountService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author ZC.GUO
 * @version 1.0
 * @date create on 2020-07-07 10:09
 */
@Component
@Slf4j
@AllArgsConstructor
@AfsJob
public class ContractFinanceTask {

    private final FinanceVirtualAccountService financeVirtualAccountService;

    @AfsJobHandler(value = "handleUnusedFunds")
    public ReturnT<String> handleUnusedFunds(String params){

        log.info("开始执行账户未分配余额处理任务");

        List<FinanceVirtualAccount> virtualAccountList = financeVirtualAccountService.list(Wrappers.<FinanceVirtualAccount>query().lambda()
                .gt(FinanceVirtualAccount::getUnUsedAmt, BigDecimal.ZERO));
        if (virtualAccountList != null && virtualAccountList.size()>0){
            for (FinanceVirtualAccount virtualAccount:virtualAccountList){
                financeVirtualAccountService.handleUnusedFundsForOne(virtualAccount);
            }
        }
        log.info("账户未分配余额处理任务执行完成");
       return ReturnT.SUCCESS;
    }
    

}
